<template>
  <div class="boxs">
    <!-- 面包屑组件 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>
        <!-- <img src="@/assets/userCenter/组132.png" alt="" /> -->
        <i class="el-icon-user-solid"></i>
        <span class="span" style="color: #666"> 用户中心</span>
      </el-breadcrumb-item>
      <el-breadcrumb-item>
        <span class="span" style="color: #666">我的报告</span>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="f1">
      <project-tab />
      <div class="title">我的报告</div>
      <div class="search_input">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          label-width="180px"
        >
          <el-form-item label="" label-width="0px">
            <el-input
              v-model="queryParams.entname"
              placeholder="请输入企业名称/统一社会信用代码"
              @keyup.enter.native="handleQuery"
            >
              <div slot="suffix" class="search_input">
                <img
                  @click="handleQuery()"
                  src="@/assets/userCenter/组26.png"
                  alt=""
                />
              </div>
            </el-input>
          </el-form-item>
          <el-form-item label="报告类型" prop="customsauthgrade">
            <el-select
              clearable
              v-model="reporttype"
              placeholder="请选择报告类型"
            >
              <el-option label="基础版" value="3"></el-option>
              <el-option label="标准版A" value="1"></el-option>
              <el-option label="标准版B" value="2"></el-option>
              <el-option label="高级版" value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <!-- 表格 -->
      <div class="table" v-if="list">
        <el-table
          :data="list"
          border
          style="width: 100%"
          :header-cell-style="{
            background: '#F1F5FF',
            color: '#4D4D4D',
          }"
        >
          <el-table-column
            prop="orderid"
            label="订单号"
            width="180"
            align="center"
            fixed="left"
          >
          </el-table-column>
          <el-table-column
            prop="entname"
            label="企业名称"
            width="300"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="codeid"
            label="统一社会信用代码"
            width="220"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="version"
            label="版本"
            align="center"
            width="180"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-show="scope.row.version == 1">标准版A</span>
              <span v-show="scope.row.version == 2">标准版B</span>
              <span v-show="scope.row.version == 3">基础版</span>
              <span v-show="scope.row.version == 4">高级版</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            width="140"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <!-- <el-tag v-show="" type="info"
                >数据采集中</el-tag
              > -->
              <el-tag v-show="scope.row.status == 2 || scope.row.status == 1"
                >生成中</el-tag
              >
              <el-tag v-show="scope.row.status == 3" type="success"
                >生成成功</el-tag
              >
              <el-tag v-show="scope.row.status == 4" type="danger"
                >生成失败</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="inputdate"
            label="生成时间"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="address"
            label="操作"
            align="center"
            width="130"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="
                  download(scope.row.id, scope.row.status, list, scope.$index)
                "
                >下载</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="delReport(scope.row.id)"
                ><span style="color: #ff4040">删除</span></el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页器 -->
      <div class="pagination" v-if="list">
        <el-pagination
          background
          layout="prev, pager, next"
          @next-click="nextClick()"
          @prev-click="prevClick()"
          @current-change="handlePageChange"
          :total="pages * 10"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
// import { bussinessReportEdit, myPostFetch } from "@/api/report/index.js";
import { Message } from "element-ui";
import { myPostFetch, downloadReport, delBussinessReport } from "@/api/report";
import ProjectTab from "@/components/ProjectTab.vue";
export default {
  components: { ProjectTab },
  data() {
    return {
      queryParams: {
        entname: "",
      },
      reporttype: "",
      businessid: "",
      pageNum: 1,
      pageSize: 10,
      pages: 1,
      list: null,
    };
  },
  watch: {
    reporttype(old, end) {
      this.reporttype = old;
      this.pageNum = 1;
      this.findkjapply();
    },
  },
  mounted() {
    document.documentElement.scrollTop = 0;
    this.businessid = localStorage.getItem("businessid");
    this.findkjapply();
  },
  methods: {
    handleClose(reportid) {
      sessionStorage.setItem("reportid", JSON.stringify(reportid));
      this.$router.push("/userCenter");
    },
    // 下载
    download(id, status, data, index) {
      if (status == 1 || status == 2) {
        this.$Message.warning("报告生成中，请稍后");
      } else if (status == 3) {
        downloadReport({
          id: id,
        })
          .then((success) => {
            let imgUrlStr = success.data.file;
            const a = document.createElement("a"); // 动态创建a标签，防止下载大文件时，用户没看到下载提示连续点击
            a.setAttribute("target", "_blank");
            a.download = data[index].file.split("/")[5].split(".")[0];
            a.href = imgUrlStr;
            a.click();
          })
          .catch(() => {
            this.$Message.error("报告下载失败");
          });
      } else {
        this.$Message.error("报告生成失败");
      }
    },
    //删除报告
    delReport(id) {
      this.$confirm("确定删除当前报告?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delBussinessReport({
            id: id,
          });
          this.$Message({
            type: "success",
            message: "报告删除成功!",
          });
          this.findkjapply();
        })
        .catch(() => {
          this.$Message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 获取信息
    async findkjapply() {
      let params = {
        reporttype: this.reporttype,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        entname: this.queryParams.entname,
        codeid: "",
      };
      let url = "/zb/getBusinessReport";
      let data = await myPostFetch(url, params);
      if (data.code == 500) return this.$Message.error(data.msg);
      this.list = data.data.list;
      this.pages = data.data.pages;
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.findkjapply();
    },
    //点击下一页
    nextClick() {
      this.pageNum += 1;
      this.findkjapply();
    },
    //点击上一页
    prevClick() {
      this.pageNum -= 1;
      this.findkjapply();
    },
    //点击数字改变page的值
    handlePageChange(currentPage) {
      this.pageNum = currentPage;
      this.findkjapply();
    },
  },
};
</script>

<style lang="scss" scoped>
.boxs {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  // 面包屑
  .breadcrumb {
    display: flex;
    align-items: center;
    height: 40px;
    font-size: 16px;
    background-color: rgb(242, 244, 247);
    .icon {
      margin: 0 10px 0 4px;
    }
    .span {
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #999999;
    }
    img {
      width: 18px;
      height: 18px;
      margin-right: 5px;
    }
  }
  .f1 {
    box-sizing: border-box;
    padding: 20px 35px;
    .title {
      font-size: 18px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #000000;
      margin-bottom: 28px;
    }
    .search_input {
      cursor: pointer;
      height: 100%;
      position: relative;
      display: flex;
      align-items: center;
      img {
        width: 16px;
        position: absolute;
        right: 6px;
      }
    }
    // 表格

    .table {
      box-sizing: border-box;
      width: 850px;
      background-color: #fff;
      height: 100%;
      margin-bottom: 20px;
      cursor: pointer;
      overflow: auto;
      margin-top: 30px;
      .span {
        display: inline-block;
        // width: 0.1563px;
        // height: 0.125px;
        font-size: 15px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        margin-right: 5px;
        color: #ccc;
        border-bottom: 1px solid #ccc;
        cursor: pointer;
        margin-right: 10px;
      }
      .span1 {
        display: inline-block;
        font-size: 15px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        margin-right: 5px;
        color: #3f6ef2;
        border-bottom: 1px solid #3f6ef2;
        cursor: pointer;
      }
      .nactive {
        font-size: 13px;
        margin-right: 5px;
        color: #3f6ef2;
        border-bottom: 1px solid #3f6ef2;
      }
      .state-bar {
        span {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #606266;
          margin-right: 10px;
        }
      }
    }
    // 分页器
    .pagination {
      display: flex;
      justify-content: right;
      span {
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #666666;
        margin-top: 2px;
      }
    }
  }
}
::v-deep .el-form {
  display: flex;
}
// 表格滚动条
::v-deep .el-table {
  th.el-table__cell > .cell {
    font-size: 16px;
    font-weight: 400;
  }
  .cell {
    font-size: 16px;
  }
  .el-table__body-wrapper {
    overflow: auto;
    height: calc(100% - 85px);

    &::-webkit-scrollbar {
      width: 0; /* 纵向滚动条 宽度 */
      height: 15px; /* 横向滚动条 高度 */
    }
    &::-webkit-scrollbar-thumb {
      width: 10px; /* 横向滚动条 宽度 */
      height: 15px; /* 纵向滚动条 高度 */
      background-color: rgb(167, 164, 164);
    }
  }
}
::v-deep .el-form-item--small .el-form-item__label {
  line-height: 37px;
  font-size: 14px;
}
/* 输入框样式  */
::v-deep .el-input__inner {
  box-sizing: border-box;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 0px;
  padding: 10px;
  color: #606266;
  outline: 0;
  line-height: 35px !important;
  width: 300px;
  height: 37px;
  background: #ffffff;
  border-radius: 4px;
}
::v-deep .el-table th.el-table__cell > .cell {
  text-align: center;
}

// 表格样式
::v-deep .el-table th.el-table__cell > .cell {
  font-size: 16px;
}
::v-deep.el-pagination {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
  font-size: 16px;
  font-family: Source Han Sans SC;
  font-weight: 400;
  color: #666666;
}
/* 表格 */
::v-deep .el-table {
  th.el-table__cell > .cell {
    font-size: 15px;
    font-weight: 400;
  }
  .cell {
    font-size: 15px;
  }
}
</style>
<style lang="scss">
/* 分页器 */
.el-pagination.is-background .el-pager li {
  border-radius: 20px;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #3f6ef2;
}

.el-pagination.is-background .btn-next,
.el-pagination.is-background .btn-prev,
.el-pagination.is-background .el-pager li {
  background-color: transparent;
}
/* 表格 */
.el-table {
  th.el-table__cell > .cell {
    font-size: 14px;
    font-weight: 400;
  }
  .cell {
    font-size: 14px;
  }
}
.el-table tr {
  height: 40px;
}
.el-table .el-table thead {
  height: 40px;
}

.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #3f6ef2;
}
</style>
